"""
本文件用于分析标注，统计图标注信息
"""

from config import generate_dataset_label_path
import json


def statics():
    Labels = {
            "Legend": 0,
            "ValueTitle": 1,
            "Title": 2,
            "CategoryTitle": 3,
            "BarCanvas": 4,
            "LineCanvas": 5,
            "PieCanvas": 6,
            "Bar": 7,
            "Line": 8,
            "Pie": 9,
            "Pictogram": 10
        }

    data_statics_li = [[0 for i in Labels.keys()] for i in range(3)]
    has_data_element = 0

    with open(generate_dataset_label_path, "r") as fp:
        labels = json.load(fp)

    for key in labels.keys():

        label = labels[key]
        data_statics = data_statics_li[label["data_type"]]
        data_statics[-1] += 1

        if label["has_data_element"]:
            has_data_element += 1

        for label_key in label.keys():
            if label_key in Labels.keys():
                value = label[label_key]
                idx = Labels[label_key]
                if Labels["Bar"] <= idx <= Labels["Pie"]:
                    data_statics[idx] += len(value)
                else:
                    data_statics[idx] += 1

    print("--------------------statics-----------------------")
    for label_key in Labels.keys():
        idx = Labels[label_key]
        print(f"{label_key}", end="\t")
        for i in range(3):
            data_statics = data_statics_li[i]
            print(f"{data_statics[idx]}", end="\t")
        print("")
    print(f"has_data_element:\t\t{has_data_element}")
    print("----------------------end-------------------------")


if __name__ == "__main__":
    statics()
